package spring.study.annotation.Condition;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author study
 * @version 1.0
 * @date 2020/6/18 23:42
 */

public class Linux implements Condition {
    /**
     * ConditionContext ：条件判断使用的上下文(环境)
     * AnnotatedTypeMetadata：注释信息
     */
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        //TODO 判断是否是Linux系统

        //1 能获取到ioc使用的 beanFactory
        ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
        //2 获取类加载器
        ClassLoader classLoader = context.getClassLoader();

        Environment environment = context.getEnvironment();
        //4 获取到bean定义的注册类
        BeanDefinitionRegistry registry = context.getRegistry();

        String osName = environment.getProperty("os.name");

        if (osName.toLowerCase().contains("wind")) {
            return false;
        }
        return true;
    }
}
